download_redis:
  cmd.run:
    - name: |
        cd /srv/files/
        wget http://download.redis.io/releases/redis-3.2.0.tar.gz
    - unless: test -f /srv/files/redis-3.2.0.tar.gz

unzip_redis:
  archive.extracted:
    - name: /usr/local/src/
    - source: /srv/files/redis-3.2.0.tar.gz
    - archive_format: tar
    - tar_options: zxvf
    - if_missing: /usr/local/src/redis-3.2.0
    - unless: test -d /usr/local/src/redis-3.2.0

install_redis:
  cmd.run:
    - name: |
        cd /usr/local/src/redis-3.2.0
        make
        make PREFIX=/usr/local/redis install
        cp ./redis.conf /usr/local/redis/
    - unless: ls /usr/local/redis

#后台作为daemon运行       daemonize yes
#开启远程访问  # 1.去掉 # bind 127.0.0.1   2. protected-mode no
#redis从服务
#slaveof <masterip> <masterport>
#slave-read-only yes
modify_redis.conf:
  file.managed:
    - name: /usr/local/redis/redis.conf
    - source: salt://redis/files/redis.conf.jinja
    - template: jinja
    
setting_service_redis:
  file.managed:
    - name:  /etc/init.d/redis
    - source: salt://redis/files/redis.jinja
    - template: jinja
    - user: root
    - group: root
    - mode: 755
    - unless: test -f /etc/init.d/redis
  cmd.run:
    #设定开机启动服务
    - name: chkconfig redis on

enable_service_redis:
  service.running:
    - name: redis
    - enable: True
    - listen:
      - file: /etc/init.d/redis
